
export const echartsSize = function (size?: number, defalteWidth?: number = 1920) {
    let docEl = document.documentElement,
        clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (!clientWidth) return;
    let fontSize = (clientWidth / defalteWidth);
    return Number((size * fontSize).toFixed(3));
}

// 设置系统缩放比，适配各分辨率
export const refreshScale = function () {
    //内容可视区域宽高
    let baseWidth = document.documentElement.clientWidth;
    let baseHeight = document.documentElement.clientHeight;
    let screenWidth = screen.width
    let screenHeight = screen.height

    let appStyle = document.getElementById('app')?.style;
    let realRatio = baseWidth / baseHeight
    let designRatio = 16 / 9
    // console.log(realRatio, designRatio)
    // console.log('baseWidth=', baseWidth, 'baseHeight=', baseHeight, 'screenWidth=', screenWidth, 'screenHeight=', screenHeight)
    let scaleRate = baseWidth / baseWidth

    scaleRate = realRatio > designRatio ? 1 : 1

    if (baseWidth < screenWidth) {
        scaleRate = realRatio > designRatio ? baseHeight / 1080 : baseWidth / 1920
    }
    appStyle.transformOrigin = 'left top';
    appStyle.transform = `scale(${scaleRate}) translateX(-50%)`;
    appStyle.width = `${baseWidth / scaleRate}px`
    appStyle.height = `${baseHeight / scaleRate}px`
    appStyle.left = `50%`
}

export const setHtmlsize = function () {
    var docEl = document.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';

    var clientWidth = docEl.clientWidth;
    if (clientWidth === undefined) return;
    docEl.style.fontSize = 18 * (clientWidth / 1920) + 'px';
}

export const getfontSize = function(res) {
    let docEl = document.documentElement,
        clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (!clientWidth) return;
    let fontSize = clientWidth / 1920;
    return res * fontSize;
}